<script setup lang="ts">
defineOptions({name:'Top'})
import {onBeforeUnmount,onMounted,ref} from "vue";
import {useRouter} from "vue-router";
import moment from 'moment'

const $router = useRouter()
/**
 * 返回首页
 */
const goHome = () => {
  $router.push('/')
}
const timer = ref()
const time = ref(moment().format('YYYY年MM月DD日 hh:mm:ss'))
//组件挂载开启定时器
onMounted(()=>{
  timer.value= setInterval(()=>{
    time.value=moment().format('YYYY年MM月DD日 hh:mm:ss')
  },1000)
})
//组件销毁情况定时器
onBeforeUnmount(()=>{
  clearInterval(timer.value)
})
</script>

<template>
  <div class="top">
    <div class="left">
      <div class="btn" @click="goHome">首页</div>
    </div>
    <div class="center">
      <div class="tit">智慧旅游可视化大数据平台</div>
    </div>
    <div class="right">
      <div class="btn">统计报告</div>
      <div class="time">
        当前时间：{{time}}
      </div>
    </div>
  </div>
</template>

<style scoped lang="scss">
.top{
  width: 100%;
  height: 40px;
  display: flex;
  .left{
    flex: 1;
    background: url("../../images/dataScreen-header-left-bg.png") no-repeat;
    background-size: cover;
    height: 40px;
    .btn{
      width: 150px;
      height: 40px;
      float: right;
      background: url("../../images/dataScreen-header-btn-bg-l.png") no-repeat;
      background-size: cover;
      color: white;
      text-align: center;
      line-height: 36px;
    }
  }
  .center{
    flex: 2;
    .tit{
      width: 100%;
      height: 70px;
      background: url("../../images/dataScreen-header-center-bg.png") no-repeat;
      background-size: cover;
      color: #c8d9ff;
      font-size: 40px;
      text-align: center;
      line-height: 70px;
    }
  }
  .right{
    flex: 1;
    height: 40px;
    background: url("../../images/dataScreen-header-right-bg.png") no-repeat;
    background-size: cover;
    .btn{
      width: 150px;
      height: 40px;
      float: left;
      background: url("../../images/dataScreen-header-btn-bg-l.png") no-repeat;
      background-size: cover;
      color: white;
      text-align: center;
      line-height: 36px;
    }
    .time{
      font-size: 16px;
      height: 40px;
      float: right;
      color: white;
      text-align: center;
      line-height: 36px;
      margin-right: 30px;
    }
  }
}
</style>